﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Commnications
{
    /// <summary>
    /// 通讯收发规范
    /// </summary>
    public interface IEasyComm
    {
        /// <summary>
        /// 是否连接成功
        /// </summary>
        bool IsConnected { get; }
        /// <summary>
        /// 发送数据，并接收指定长度数据
        /// </summary>
        /// <param name="cmd">发送命令</param>
        /// <param name="len">长度</param>
        /// <param name="sendFirst">是否先发送后接收</param>
        /// <returns>响应</returns>
        EasyResultT<byte[]> Read(byte[] cmd, int len, bool sendFirst = true);
        /// <summary>
        /// 写数据
        /// </summary>
        /// <param name="cmd">发送命令</param>
        /// <returns>是否写命令成功</returns>
        EasyResult Write(byte[] cmd);
        /// <summary>
        /// 接收数据
        /// </summary>
        /// <param name="data">结果记录</param>
        //void OnDataArrive(EasyResult data);

        /// <summary>
        /// 设置读取超时（单位ms）
        /// </summary>
        int ReadTimeout { get; set; }
        /// <summary>
        /// 设置写超时（单位ms）
        /// </summary>
        int WriteTimeout { get; set; }
    }
}
